/**   
 * Copyright © 2016 北京之洲科技有限责任公司. All rights reserved.
 * 
 * @Title: BussinessDaoOfAutoHome.java 
 * @Prject: carfactory
 * @Package: com.zizo.autohome.business.dao 
 * @Description: 
 * @author: Alexis  
 * @email heyan0227@outlook.com
 * @date: 2016年8月11日 上午10:17:50 
 * @version: V1.0   
 */
package com.zizo.autohome.business.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

import com.zizo.autohome.business.bean.AutoHomeBusiness;
import com.zizo.core.DAO;
import com.zizo.core.T;
import com.zizo.util.Util;

/**
 * @ClassName: BussinessDaoOfAutoHome
 * @Description:
 * @author: Alexis
 * @date: 2016年8月11日 上午10:17:50
 */
public class BusinessDaoOfAutoHome extends DAO {

	/**
	 * @Title:BussinessDaoOfAutoHome
	 * @Description:
	 * @param currConn
	 */
	public BusinessDaoOfAutoHome(Connection currConn) {
		super(currConn);
	}

	/*
	 * (non Javadoc)
	 * 
	 * @Title: getIDs
	 * 
	 * @Description:
	 * 
	 * @return
	 * 
	 * @see com.zizo.core.DAOInterface#getIDs()
	 */
	@Override
	public List<String> getIDs() {
		// TODO Auto-generated method stub
		return null;
	}

	/*
	 * (non Javadoc)
	 * 
	 * @Title: insertData
	 * 
	 * @Description: 插入经销商的基本信息
	 * 
	 * @param t
	 * 
	 * @return
	 * 
	 * @see com.zizo.core.DAOInterface#insertData(com.zizo.core.T)
	 */
	@Override
	public int insertData(T t) {
		PreparedStatement ps = null;
		AutoHomeBusiness business = (AutoHomeBusiness) t;
		Map<Integer, Integer> map = business.getCars();
		for (int i : map.keySet()) {
			int type = map.get(i);
			insertCars(type, i, business.getDealerId());
		}
		String sql = "REPLACE INTO autohome_other.other_business(business_4s,business_ministieName,business_address,business_phone,business_cityName,business_mainBand,business_hasAuth,business_mapLonBaidu,business_mapLatBaidu,business_uptime) VALUES(?,?,?,?,?,?,?,?,?,?)";
		try {
			ps = currConn.prepareStatement(sql);
			ps.setInt(1, business.getDealerId());
			ps.setString(2, business.getMinistieName());
			ps.setString(3, business.getAddress());
			ps.setString(4, business.getPhone());
			ps.setString(5, business.getCityName());
			ps.setString(6, business.getMainBand());
			ps.setInt(7, business.getHasAuth());
			ps.setDouble(8, business.getMapLonBaidu());
			ps.setDouble(9, business.getMapLatBaidu());
			ps.setTimestamp(10, (Timestamp) Util.getTimeHMS(Util.getCurrentDateTime()));
			ps.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return 0;
	}

	/**
	 * @Title: insertCars
	 * @Description:向qczj_business_cars表插入给定经销商ID的经营汽车ID和信息
	 * @param type
	 * @param ppid
	 * @param id
	 * @return: void
	 * @author: Alexis
	 */
	public void insertCars(int type, int ppid, int id) {
		PreparedStatement ps = null;
		String sql = "REPLACE INTO autohome_other.other_business_cars(cars_4s,cars_type,cars_brdid,cars_uptime) VALUES(?,?,?,?)";
		try {
			ps = currConn.prepareStatement(sql);
			ps.setInt(1, id);
			ps.setInt(2, type);
			ps.setInt(3, ppid);
			ps.setTimestamp(4, (Timestamp) Util.getTimeHMS(Util.getCurrentDateTime()));
			ps.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	/*
	 * Util (non Javadoc)
	 * 
	 * @Title: updateTime
	 * 
	 * @Description:
	 * 
	 * @param type
	 * 
	 * @param id
	 * 
	 * @see com.zizo.core.DAOInterface#updateTime(java.lang.String,
	 * java.lang.String)
	 */
	@Override
	public void updateTime(String type, String id) {
		// TODO Auto-generated method stub

	}

	/*
	 * (non Javadoc)
	 * 
	 * @Title: getTables
	 * 
	 * @Description:
	 * 
	 * @return
	 * 
	 * @see com.zizo.core.DAOInterface#getTables()
	 */
	@Override
	public List<String> getTables() {
		// TODO Auto-generated method stub
		return null;
	}

	/*
	 * (non Javadoc)
	 * 
	 * @Title: insertError
	 * 
	 * @Description:
	 * 
	 * @param t
	 * 
	 * @return
	 * 
	 * @see com.zizo.core.DAOInterface#insertError(com.zizo.core.T)
	 */
	@Override
	public int insertError(T t) {
		// TODO Auto-generated method stub
		return 0;
	}

}
